﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using Microsoft.SharePoint;

namespace SecurityParser
{
    public class SecurityParser
    {

        public void Parse(string fileName, SPWeb web)
        {
            //Read in the 'elements' file
            //deserialize it using the embedded schema
            XmlSerializer s = new XmlSerializer(typeof(Web));
            Web rootWeb;

            if (File.Exists(fileName))
            {
                using (XmlReader rdr = XmlReader.Create(File.OpenRead(fileName)))
                {
                    rootWeb = (Web)s.Deserialize(rdr);
                }

                if (rootWeb != null)
                {
                    //Start parsing from the root
                    rootWeb.Parse(web);
                }

            }
            else
            {
                throw new FileNotFoundException("Unable to parse elements file");
            }

        }
    }
}
